{% extends 'base.html' %}
{% load i18n %}

{% load humanize %}

{% block head %}
    <link href="{{ STATIC_URL }}css/questions.css" rel="stylesheet">
    <script src="{{ STATIC_URL }}js/questions.js"></script>
{% endblock head %}

{% block main %}
    <ol class="breadcrumb">
        <li><a href="{% url 'questions' %}">{% trans "Questions" %}</a></li>
        <li class="active">{% trans "Question" %}</li>
    </ol>
    <div class="row question" question-id="{{ question.id }}">
        {% csrf_token %}
        <div class="col-md-1 options">
            {% if user.is_anonymous %}
                <span class="glyphicon glyphicon-star favorited"
                      title={% trans 'Click to mark this question as favorite; click again to toggle' %}></span>
            {% elif user in question.get_favoriters %}
                <span class="glyphicon glyphicon-star favorite favorited"
                      title={% trans 'Click to mark this question as favorite; click again to toggle' %}></span>
            {% else %}
                <span class="glyphicon glyphicon-star-empty favorite"
                      title={% trans 'Click to mark this question as favorite; click again to toggle' %}></span>
            {% endif %}
            <span class="favorite-count">{{ question.favorites }}</span>
        </div>
        <div class="col-md-11">
            <h2>{{ question.title }}</h2>

            <div class="question-user">
                <a href="{% url 'profile' question.user.username %}"><img src="{{ question.user.profile.get_picture }}"
                                                                          class="user"></a>
                <a href="{% url 'profile' question.user.username %}"
                   class="username">{{ question.user.profile.get_screen_name }}</a>
                <small class="asked">{% trans 'asked' %} {{ question.update_date|naturaltime }}</small>
            </div>
            <div class="question-description">
                {{ question.get_description_as_markdown|safe }}
            </div>
            {% if question.get_tag_list %}
                <p>
                    {% for tag in question.get_tag_list %}
                        <span class="label label-primary">{{ tag }}</span>
                    {% endfor %}
                </p>
            {% endif %}
        </div>
    </div>
    <h4 class="page-header">{% trans 'Answers' %}</h4>
    <div class="answers">
        {% for answer in question.get_answers %}
            {% include 'questions/partial_answer.html' with question=question answer=answer %}
        {% endfor %}

        {% if not user.is_anonymous %}
            <h4>{% trans 'Your Answer' %}</h4>

            <form action="{% url 'answer' %}" method="post" role="form">
                {% csrf_token %}
                {{ form.question }}
                <div class="form-group">
                    {% include 'markdown_editor.html' with textarea='id_description' %}
                    {{ form.description }}
                </div>
                <div class="form-group">
                    <button type="submit" class="btn btn-primary">{% trans "Post Your Answer" %}</button>
                </div>
            </form>
        {% endif %}
    </div>
{% endblock main %}
